package com.socialuni.center.web.serive.talk;

import com.socialuni.sdk.api.model.RO.talk.SocialTalkRO;
import com.socialuni.center.web.utils.CenterTalkUtil;
import com.socialuni.sdk.constant.status.ContentStatus;
import com.socialuni.sdk.exception.SocialParamsException;
import com.socialuni.sdk.factory.TalkROFactory;
import com.socialuni.sdk.model.DO.user.UserDO;
import com.socialuni.sdk.model.DO.talk.TalkDO;
import com.socialuni.center.web.utils.CenterUserUtil;
import com.socialuni.sdk.api.model.ResultRO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * @author qinkaiyuan
 * @date 2020-05-16 20:11
 */
@Service
@Slf4j
public class CenterTalkDetailService {
    public ResultRO<SocialTalkRO> queryTalkDetail(String talkId) {
        UserDO mineUser = CenterUserUtil.getMineUser();

        TalkDO talkDO = CenterTalkUtil.get(talkId);

        //自己的动态可以看预审核
        if (CenterUserUtil.isMine(talkDO.getUserId())) {
            if (!ContentStatus.selfCanSeeContentStatus.contains(talkDO.getStatus())) {
                throw new SocialParamsException("无法查看不存在的动态");
            }
        } else {
            if (!ContentStatus.otherCanSeeContentStatus.contains(talkDO.getStatus())) {
                throw new SocialParamsException("无法查看不存在的动态");
            }
        }

        SocialTalkRO talkRO = TalkROFactory.getTalkDetailPageTalkRO(mineUser, talkDO, true);

        return new ResultRO<>(talkRO);
    }
}
